package cn.chenwx.bbsforum.mapper;

import cn.chenwx.bbsforum.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface UserMapper {

    @Select("select * from user")
    List<User> findAllUser();
    @Select("select * from user where id=#{id}")
    User findUserById(@Param("id") int id);
    @Insert("insert into user(id,username,password,role,sex,email,phone)values(#{id},#{username},#{password},#{role},#{sex},#{email},#{phone})")
    int addUser(User user);
    @Update("update user set username=#{username},password=#{password},sex=#{sex},email=#{email},phone=#{phone} where id=#{id}")
    int modifyUser(User user,@Param("id") int id);

    @Update("update user set username=#{user.username} where id=#{id}")
    int updateUser(@Param("user")User user,@Param("id")int id);
    @Delete(" delete from user where id=#{id}")
    int deleteUser(@Param("id") int id);
    @Select("select * from user where username=#{name}")
    User findUserByName(@Param("name") String name);
    @Select("select count(1) from user")
    int getUserNum();

    @Update("update user set status=#{status} where id=#{id}")
    int updateUserStatus(@Param("status")int status,@Param("id")int id);
    @Update("update user set avatarImgUrl=#{avatarImgUrl} where id=#{id}")
    void updateAvatarImgUrlById(@Param("avatarImgUrl") String avatarImgUrl, @Param("id") int id);

    @Select("select avatarImgUrl from user where id=#{id}")
    String getHeadPortraitUrl(int userId);
    @Select("select * from user where username=#{username}")
    User getUserPersonalInfoByUsername(String username);
    @Select("select * from user where username=#{username}")
    User findUsernameByUsername(String username);
    @Update("update user set username=#{user.username},sex=#{user.sex},creatTime=#{user.creatTime},email=#{user.email} where username=#{username}")
    void savePersonalDate(@Param("user") User user, @Param("username") String username);

}

